/**
 *  EKology - An Ecosystem Simulation Framework
 *  Copyright (C) 2008  Aarón Tavío - aaron.tavio at gmail.com - ULPGC
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package net.ekology.core.datatypes;

import java.io.Serializable;


/**
 * A <code>Signal</code> is needed to obtain information from the ecosystem.
 * 
 * @author Aarón Tavío - aaron.tavio at gmail.com
 * @version 1.0.0 - 20081019-1700
 */
public class Signal implements Serializable {
    private String sName;
    private SignalType oType;
    private long lInterval;
    private long lElapsedTime;
    private SignalStatusType oStatus;
    
    
    
    public Signal(String sName, SignalType oType, long lInterval) {
        this.sName = sName;
        this.oType = oType;
        this.lInterval = lInterval;
        lElapsedTime = 0;
        oStatus = SignalStatusType.DISABLED;
    }
    
    
    public Signal(String sName, SignalType oType, long lInterval, SignalStatusType oStatus) {
        this.sName = sName;
        this.oType = oType;
        this.lInterval = lInterval;
        this.oStatus = oStatus;
        lElapsedTime = 0;
    }
    
    
    public String getName() {
        return sName;
    }
    
    public SignalType getType() {
        return oType;
    }
    
    public long getInterval() {
        return lInterval;
    }
    
    public void setInterval(long lInterval) {
        this.lInterval = lInterval;
    }
    
    public void setStatus(SignalStatusType oStatus) {
        this.oStatus = oStatus;
    }
    
    
    public SignalStatusType getStatus() {
        return oStatus;
    }
   
    
    
    /**
     * Adds the elapsed time to the <code>Signal</code>
     * <p>
     * When the elapsed time is grater than the interval defined by the <code>Signal</code>,
     * this is triggered
     * 
     * @param lElapsedTime measured in milliseconds
     * @return whether the signal is triggered or not
     */
    public boolean addElapsedTime(long lElapsedTime) {
        if (oStatus != oStatus.DISABLED) {
            this.lElapsedTime += lElapsedTime;
        
            if (this.lElapsedTime > lInterval) {
                this.lElapsedTime -= lInterval;
                return true;
            }
            else return false;
        }
        else return false;
        
    }
}
